//
//  MineViewController.swift
//  FirstSwiftProduct
//
//  Created by 知合金服-Mini on 2017/10/27.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

class MineViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource {
    
    
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 10))
        return headView
    }
    func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let headView = UIView.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 10))
        return headView
    }
    
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.separatorInset = .zero
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.01
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {
        case 1:
            return 4
        default:
            return 1
        }
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0 {
            return 80
        }
        return 40
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if indexPath.section != 0 {
            let cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "cellId")
            cell.imageView?.image = UIImage.init(named: nameArr[indexPath.section][indexPath.row])
            cell.textLabel?.text = titleArr[indexPath.section][indexPath.row]
            cell.selectionStyle = .none
            cell.accessoryType = .disclosureIndicator
            return cell
        }else{
            let cell = MineCell()
            
            cell.headImageView?.image = UIImage.init(named: "father")
            cell.headLabel?.text = "Kobe Bryant"
            let str = "我也不知道是个什么号: 1313113"
            
            let attr = NSMutableAttributedString.init(string: str)
            attr.addAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 14)], range: NSMakeRange(0, 11))
            attr.addAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 16)], range: NSMakeRange(11, str.count - 11))
            
            cell.headDetailLabel.attributedText = attr
            cell.selectionStyle = .none
            cell.accessoryType = .disclosureIndicator
            return cell
        }
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        switch indexPath.section {
        case 0:
            let info = InfomationViewController()
            self.navigationController?.pushViewController(info, animated: true)
            break
        case 1:
            if indexPath.row == 0{
                let collectVC = CollectionViewController()
                self.navigationController?.pushViewController(collectVC, animated: true)
            }
             
             
            break
        case 2:
            //钱包
            break
        case 3:
            //设置
            let setVC = SettingViewController()
            self.navigationController?.pushViewController(setVC, animated: true)
            
            break
        
        default:
            break
        }
        
        
    }
    
    
    
    
    var mineTableView : UITableView!
    let nameArr = [[""],["MoreMyFavorites","MoreMyAlbum","MyCardPackageIcon","MoreExpressionShops"],["MoreMyBankCard"],["MoreSetting"]]
    let titleArr = [[""],["收藏","相册","卡包","表情"],["钱包"],["设置"]]
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBarController?.tabBar.isHidden = false
        self.titleLabel.text = "我的"
        // Do any additional setup after loading the view.
//        let backView = UIView.init(frame: CGRect(x: 0, y:0, width: SCREEN_WIDTH, height: SCRENN_HEIGHT))
////        backView.backgroundColor = UIColor.red
//        backView.isMultipleTouchEnabled = true
//        let tapV = TapMoveView.init(frame: CGRect(x: 20, y: 20 , width: 40, height: 40))
//        //     tapV.imageArr = ["w","n","m","d"]
//        tapV.backgroundColor = UIColor.gray
//        view.addSubview(backView)
//        backView.addSubview(tapV)
        
        
        mineTableView = UITableView.init(frame: CGRect(x: 0, y: CGFloat(kStatus_Navigation_height), width: SCREEN_WIDTH, height: SCRENN_HEIGHT - CGFloat(kStatus_Navigation_height)), style: UITableViewStyle.grouped)
        mineTableView.delegate = self
        mineTableView.dataSource = self
//        mineTableView.backgroundColor = UIColor.red
        mineTableView.register(MineCell.classForCoder(), forCellReuseIdentifier: "MineCell")
        
        mineTableView.separatorInset = UIEdgeInsets.zero
        view.addSubview(mineTableView)

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidLayoutSubviews() {
        
    }
//    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
